<?php

   @include_once('connect.php');

    $res = [];

    $username = $_POST['username'];
    $password = $_POST['password'];

    // $username = 'bb';
    // $password = 12;

    if($username && $password){
        $sql = "SELECT * FROM user2 WHERE username='$username'";
        $ggo = mysqli_query($connect , $sql);
        $arr = mysqli_fetch_array($ggo);

        if($arr){
            //找到用户判断密码是否正确
            //arr是关联数组，可以直接找密码
            if($arr['password'] == $password){
                //密码正确跳转到商品详情页
                $res['status'] = true;
                $res['msg'] = '登录成功';
                
            }else{
                $res['status'] = false;
                $res['msg'] = '密码错误';
            }

        }else{
            $res['status'] = false;
            $res['msg'] = '用户不存在,请先注册';
        }
    }else{
        $res['status'] = false;
        $res['msg'] = '前端数据错误';
    }
    echo(json_encode($res,JSON_UNESCAPED_UNICODE));

    
    